package com.fenghuo.map;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.fenghuo.model.Histroy;
import com.fenghuo.utils.CustomToast;
import com.fenghuo.utils.UtilPrefference;
import com.fenghuo.utils.Values;

import net.tsz.afinal.FinalActivity;
import net.tsz.afinal.FinalDb;
import net.tsz.afinal.annotation.view.ViewInject;

public class Ac_Settings extends FinalActivity {

    @ViewInject(id = R.id.tv_back_setttings, click = "onClick")
    TextView tv_back;
    @ViewInject(id = R.id.rela_clearhis, click = "onClick")
    RelativeLayout rela_clear;
    @ViewInject(id = R.id.rela_voice, click = "onClick")
    RelativeLayout rela_usemc;
    @ViewInject(id = R.id.chb_usemc)
    CheckBox chb_usemc;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
//		System.out.println("Ac_Settings.onCreate()1");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ac_settings);

        String usemc = UtilPrefference.getpreffer(Ac_Settings.this, UtilPrefference.settingfile, "usemc");
        boolean b = Boolean.parseBoolean(usemc);
        chb_usemc.setChecked(b);
    }

    @Override
    protected void onDestroy() {
//		System.out.println("Ac_Settings.onDestroy()5");
        super.onDestroy();
    }

    @Override
    protected void onStop() {
//		System.out.println("Ac_Settings.onStop()4");
        super.onStop();
    }

    @Override
    protected void onRestart() {
//		System.out.println("Ac_Settings.onRestart()11");
        super.onRestart();
    }

    @Override
    protected void onStart() {
//		System.out.println("Ac_Settings.onStart()2");
        super.onStart();
    }

    @Override
    protected void onResume() {
//		System.out.println("Ac_Settings.onResume()3");
        super.onResume();
    }

    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_back_setttings:
                finish();
                break;
            case R.id.rela_voice:
                chb_usemc.setChecked(!chb_usemc.isChecked());
                UtilPrefference.write(Ac_Settings.this, UtilPrefference.settingfile, "usemc", chb_usemc.isChecked() + "");
                break;
            case R.id.rela_clearhis:
                new AlertDialog.Builder(Ac_Settings.this)
                        .setTitle("确定删除？")
                        .setPositiveButton("删除", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                FinalDb db = FinalDb.create(Ac_Settings.this, Values.DB_NAME);
                                db.deleteAll(Histroy.class);
                                new CustomToast(Ac_Settings.this).ShowMsg("删除成功！", CustomToast.Img_Ok);
                            }
                        })
                        .setNegativeButton("取消", null)
                        .show();
            default:
                break;
        }
    }


}
